package cn.ecnu.controller.match;

import cn.ecnu.common.utils.R;
import cn.ecnu.mapper.match.MatchCandidateMapper;
import cn.ecnu.pojo.match.MatchForCandidate;
import cn.ecnu.pojo.match.MatchForRecommender;
import cn.ecnu.pojo.personal.Title;
import cn.ecnu.pojo.recommend.RecommendJob;
import cn.ecnu.pojo.recommend.RecommendRequire;
import cn.ecnu.pojo.resume.ResumeExp;
import cn.ecnu.service.match.MatchCandidateService;
import cn.ecnu.service.match.MatchRecommenderService;
import cn.ecnu.service.personal.TitleService;
import cn.ecnu.service.recommend.RecommendJobService;
import cn.ecnu.service.recommend.RecommendRequireService;
import cn.ecnu.service.resume.ResumeExpService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/match")
public class MatchController {
    @Resource
    TitleService titleService;

    @Resource
    MatchCandidateService matchCandidateService;
    @Resource
    RecommendJobService recommendJobService;

    @GetMapping("/find_recommender")
    public R candidateFindRecommender(@RequestParam("userId") Integer userId){
        List<MatchForCandidate> list = matchCandidateService.list(Wrappers.<MatchForCandidate>lambdaQuery()
                .eq(MatchForCandidate::getCandidateId, userId)
                .select(MatchForCandidate::getRecommenderId)
                .orderByDesc(MatchForCandidate::getSynthesis));
        List<Title> result = new ArrayList<>();
        for (MatchForCandidate matchForCandidate : list) {  //TODO 此处性能可以优化，这里偷懒了不用管
            Integer recommenderId = matchForCandidate.getRecommenderId();
            Title title = titleService.getById(recommenderId);
            result.add(title);
        }
        return R.data(result);
    }

    @Resource
    MatchRecommenderService matchRecommenderService;
    @Resource
    ResumeExpService resumeExpService;

    @GetMapping("/find_candidate")
    public R recommenderFindCandidate(@RequestParam("userId") Integer userId){
        List<MatchForRecommender> list = matchRecommenderService.list(Wrappers.<MatchForRecommender>lambdaQuery()
                .eq(MatchForRecommender::getRecommenderId, userId)
                .select(MatchForRecommender::getCandidateId)
                .orderByDesc(MatchForRecommender::getSynthesis));
        List<Title> result = new ArrayList<>();
        for (MatchForRecommender matchForRecommender : list) {  //TODO 此处性能可以优化，这里偷懒了不用管
            Integer candidateId = matchForRecommender.getCandidateId();
            Title title = titleService.getById(candidateId);
            result.add(title);
        }
        return R.data(result);
    }

}
